package com.tiger.bodyselfcheck;

import java.text.DecimalFormat;

import net.youmi.android.AdListener;
import net.youmi.android.AdManager;
import net.youmi.android.AdView;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

public class ResultActivity extends Activity  implements AdListener {
	static {
		// 应用Id 应用密码 广告请求间隔(s) 测试模式 应用版本号
		AdManager.init("fb17728f5d2b3519", "8b93cc3e7be96690", 31, false, 2.1);
	}
	private Bundle bundle;
 	private Button redo;
 	private TextView tizhong,xiongwei,yaowei,tengwei;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.result);
        
        setAdView();
        tizhong=(TextView)this.findViewById(R.id.tizhong);
        xiongwei=(TextView)this.findViewById(R.id.xiongwei);
        yaowei=(TextView)this.findViewById(R.id.yaowei);
        tengwei=(TextView)this.findViewById(R.id.tengwei);
        bundle= this.getIntent().getExtras();
        int shengao=Integer.parseInt(bundle.getString("shengao"));
        int sexInt=bundle.getInt("sex");
        Log.i("MMALL", "sex recevice:"+sexInt);
        Log.i("MMALL", "shengao recevice:"+shengao);
        
        if(sexInt==0){
        	tizhong.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.81*(shengao-100))+"</font>公斤"));
        	xiongwei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.52*shengao)+"</font>厘米"));
        	yaowei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.37*shengao)+"</font>厘米"));
        	tengwei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.54*shengao)+"</font>厘米"));
        }else{
        	tizhong.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)1.0*(shengao-105))+"</font>公斤"));
        	xiongwei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.48*shengao)+"</font>厘米"));
        	yaowei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.47*shengao)+"</font>厘米"));
        	tengwei.setText(Html.fromHtml("<font color='#f39800'>"+formatFloat((float)0.51*shengao)+"</font>厘米"));
        }
        redo=(Button)this.findViewById(R.id.redo);
        redo.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(ResultActivity.this,MainActivity.class);
				ResultActivity.this.startActivity(intent);
			}
        });
    }
    public String formatFloat(float num){
    	DecimalFormat dg=new DecimalFormat("0.00"); //保留两位小数
    	String strnum2=dg.format(num);
    	return strnum2;
    }
    void setAdView() {
		// 初始化广告视图
		AdView adView = new AdView(this, Color.GRAY, Color.WHITE, 100);

		// 设置监听者(可以不设置，对获取广告没有影响)
		adView.setAdListener(this);

		FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
				FrameLayout.LayoutParams.FILL_PARENT,
				FrameLayout.LayoutParams.WRAP_CONTENT);

		// 设置广告出现的位置(悬浮于底部)
		params.bottomMargin = 0;
		params.gravity = Gravity.BOTTOM;

		// 将广告视图加入Activity中
		addContentView(adView, params);
	}
	@Override
	public void onConnectFailed(AdView arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onReceiveAd(AdView arg0) {
		// TODO Auto-generated method stub
		
	}
}